using System;
using System.Collections.Generic;
using UnityEngine;

public class DocStantion : MonoBehaviour
{
	[Serializable]
	private struct DocLight
	{
		public GameObject onLight;

		public GameObject offLight;
	}

	[SerializeField]
	private AudioSource _dropPixelmon;

	[SerializeField]
	private DocLight[] _docLight;

	[SerializeField]
	private PunTeams.Team _team;

	[SerializeField]
	private Transform[] _points;

	public Transform pointerOnDocStantio;

	private int _currentPoint;

	private List<GameObject> _listPixelmonsMini = new List<GameObject>();

	private NJGMapItem iconMiniMap;

	public static event Action<PunTeams.Team> OnStantionCollision;

	private void Awake()
	{
		iconMiniMap = base.gameObject.AddComponent<NJGMapItem>();
		iconMiniMap.SetType("DocStantion");
	}

	private void OnTriggerEnter(Collider other)
	{
		PlayerBehavior componentInParent = other.GetComponentInParent<PlayerBehavior>();
		if (componentInParent != null && componentInParent.isMine && componentInParent.localTeam == _team && DocStantion.OnStantionCollision != null)
		{
			DocStantion.OnStantionCollision(_team);
		}
	}

	public void SpawnCaughtPixelmon(GameObject pixelmon)
	{
		if (pixelmon != null && _currentPoint < _points.Length)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate(pixelmon);
			gameObject.transform.SetParent(base.transform);
			gameObject.transform.position = _points[_currentPoint].position;
			gameObject.transform.rotation = _points[_currentPoint].rotation;
			gameObject.transform.localScale = Vector3.one;
			_points[_currentPoint].gameObject.SetActive(true);
			SwitchLight(true, _currentPoint);
			_dropPixelmon.volume = VolumeController.VolumeSound;
			_dropPixelmon.Play();
			_currentPoint++;
			_listPixelmonsMini.Add(gameObject);
		}
	}

	public void ClearPixelmon()
	{
		foreach (GameObject item in _listPixelmonsMini)
		{
			UnityEngine.Object.Destroy(item);
		}
		for (int i = 0; i < _docLight.Length; i++)
		{
			SwitchLight(false, i);
		}
		Transform[] points = _points;
		foreach (Transform transform in points)
		{
			transform.gameObject.SetActive(false);
		}
		_currentPoint = 0;
		_listPixelmonsMini.Clear();
	}

	public void SwitchLight(bool onLight, int index)
	{
		if (index < _docLight.Length)
		{
			_docLight[index].onLight.SetActive(onLight);
			_docLight[index].offLight.SetActive(!onLight);
		}
	}
}
